
const express=require("express");
const app=express();
const mysql=require("mysql");
const conn=mysql.createConnection({
    host:"127.0.0.1",
    user:"root",
    password:"root",
    database:"node_001"
});

// app.get("/",(req,res)=>{;
//     const  sql="insert  into  user  values(null,'zs',12,1)";
//     conn.query(sql,(err,result)=>{
//         console.log(result);
//     });
// });


// 新增
// const  obj={name:"张三",age:12,gender:1};
// const  sql="insert  into  user  set ?";
// conn.query(sql,obj,(err,result)=>{
//     if(err) return  console.log("插入数据库失败"+err.message);
//     console.log(result);
// });

/* 修改 */
// const  obj={id:3,name:"张三22",age:12,gender:1};
// const  sql="update  user set ? where  id=?";
// conn.query(sql,[obj,obj.id],(err,result)=>{
//     if(err) return  console.log("插入数据库失败"+err.message);
//     console.log(result);
// });


/* 删除 */
// const  obj={id:6,name:"张三22",age:12,gender:1};
// const  sql="delete from  user  where  id=?";
// conn.query(sql,[obj.id],(err,result)=>{
//     if(err) return  console.log("插入数据库失败"+err.message);
//     console.log(result);
// });
const  sql="delete from  user  where  id=?";
conn.query(sql,8,(err,result)=>{
    if(err) return  console.log("插入数据库失败"+err.message);
    console.log(result);
});














app.listen(1600,()=>{
    console.log('server running at http://127.0.0.1:1600'); 
});

